package com.qianfeng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianfeng.common.Constants;
import com.qianfeng.entity.dto.Admin;
import com.qianfeng.entity.dto.Merchant;
import com.qianfeng.entity.vo.MyPage;
import com.qianfeng.mapper.MerchantMapper;
import com.qianfeng.utils.MyUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class MerchantService extends ServiceImpl<MerchantMapper , Merchant> {

    @Transactional(readOnly = true)
    public Merchant getByUsername(String username) {
        QueryWrapper<Merchant> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Merchant::getUsername , username);
        return this.getOne(wrapper);
    }

    @Transactional(readOnly = true)
    public MyPage<Merchant> listPage(Long pageNum) {
        IPage<Merchant> page = this.page(new Page<>(pageNum, Constants.PAGE_SIZE));
        MyPage<Merchant> myPage = MyUtils.getMyPage(page);
//        MyPage<Merchant> myPage = new MyPage<>();
//        myPage.setObjList(page.getRecords());
//        Long pages = page.getPages();
//        List<Integer> pageList = new ArrayList<>(pages.intValue());
//        for (int i = 1; i <= pages; i++) {
//            pageList.add(i);
//        }
//        myPage.setPageList(pageList);
        return myPage;
    }
}
